package cn.wx.scholar.core.entity;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableName;
import cn.wx.common.persistence.base.BaseEntity;
import cn.wx.common.utils.JSONUtils;

/**
 * <p>
 * 
 * </p>
 *
 * @author  
 * @since 2018-07-06
 */
@TableName("txt_data_4")
public class TxtData extends BaseEntity {

	private String id;
	private String authorsName;
	private String authorsOrg;
	private String year;
	private String title;
	private String doi;
	private String url;
	private String publisher;
	private String keywords;
	private String fos;
	
	private String references;
	private String issn;
	private String isbn;
	
	@TableField(exist = false)
	private List<TxtAuthors> authors;
	private Integer txtFile;
	
	/**
	 * 论文语言
	 */
	private String lang;
	
	/**
	 * 摘要
	 */
	@JSONField(name="abstract")
	private String fAbstract;
	
	/**
		doc_type": "Conference"    会议
		"doc_type": "Journal"    期刊
		"doc_type": "BookReferenceEntry"    图书引文
		"doc_type": "Conference"  ，就算会议
	 */
	private String docType;
	
	private String venue;
	
	private Integer issue;
	
	/**
	 * 论文的引用数
	 */
	@JSONField(name="n_citation")
	private Integer nCitation;
	
	/**
	 * 期刊第几卷
	 */
	private String volume;
	
	
	/**
	 * 获取fos的数组集合
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<String> getFosArray(){
		if(StringUtils.isBlank(fos)) {
			return null;
		}
		List<String> fos_ = JSONUtils.p(fos, List.class);
		return fos_;
	}
	
	/**
	 * 构建导出csv文件的集合
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<Object> newArrayObjDatas(){
		
		List<Object> l = new ArrayList<>();
		l.add(id);
		l.add(year);
		l.add(title);
		l.add(doi);
		l.add(publisher);
		
		List<String> keywords_ = JSONUtils.p(keywords, List.class);
		
		if(keywords_!=null && keywords_.size()>500) {
			l.add(JSONUtils.c(keywords_.subList(0, 500)));
		}else {
			l.add(keywords);
		}
		
		
		List<String> fos_ = JSONUtils.p(fos, List.class);
		
		if(fos_!=null && fos_.size()>500) {
			l.add(JSONUtils.c(fos_.subList(0, 500)));
		}else {
			l.add(fos);
		}
		
		
		l.add(lang);
		l.add(docType);
		l.add(references);
		l.add(isbn);

		if(authors != null && authors.size() > 0) {
			List<String> sb = new ArrayList<>();
			int i = 1;
			for(TxtAuthors a : authors) {
				if(i > 500) {
					break;
				}
				sb.add(a.getName());
				i++;
			}
			l.add(JSONUtils.c(sb));
			
		}else {
			l.add(null);
		}
		return l;
	}
	
	
	/**
	 * 东南大学数据消歧用
	 * @return
	 * header.add("Id");
	 *  header.add("Title");
	 *  header.add("Year");
	 *  header.add("ConferenceId");
	 *  header.add("JournalId");
	 *  header.add("Keywords");
	 */
	public List<Object> paperArrayDatas(){
		
		List<Object> l = new ArrayList<>();
		//l.add(id);
		l.add(title.replace("\"", "'"));
		l.add(year);
		l.add(null);
		l.add(null);
		//处理keywords
		if(StringUtils.isNotBlank(keywords)) {
			@SuppressWarnings("unchecked")
			List<String> keywords_ = JSONUtils.p(keywords, List.class);
			int z = 0;
			StringBuffer sb = new StringBuffer();
			for(String sk : keywords_) {
				if(z < keywords_.size()-1) {
					sb.append(sk).append("/t");
				}else {
					sb.append(sk);
				}
				z++;
			}
			l.add(sb.toString());
		}else {
			l.add(null);
		}
		
		l.add(doi);
		l.add(url);
		l.add(fos);
		l.add(publisher);
		l.add(fAbstract);
		l.add(docType);
		l.add(venue);
		l.add(issue);
		l.add(nCitation);
		l.add(volume);
		l.add(lang);
		return l;
	}

	public List<TxtData> newArrayTxtDatas(){
		
		List<TxtData> l = new ArrayList<>();
		TxtData st = null;
		
		if(authors != null && authors.size() > 0) {
			for(TxtAuthors a : authors) {
				st = new TxtData();
				st.setId(id);
				st.setTitle(title);
				st.setDoi(doi);
				st.setAuthorsName(a.getName());
				st.setAuthorsOrg(a.getAffiliation());
				st.setUrl(url);
				st.setYear(year);
				st.setKeywords(keywords);
				st.setFos(fos);
				st.setPublisher(publisher);
				st.setTxtFile(txtFile);
				st.setfAbstract(fAbstract);
				st.setDocType(docType);
				st.setVenue(venue);
				st.setIssue(issue);
				st.setnCitation(nCitation);
				st.setVolume(volume);
				st.setLang(lang);
				l.add(st);
			}
			return l;
		}else {
			l.add(this);
			return l;
		}
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getAuthorsName() {
		return authorsName;
	}

	public void setAuthorsName(String authorsName) {
		this.authorsName = authorsName;
	}

	public String getAuthorsOrg() {
		return authorsOrg;
	}

	public void setAuthorsOrg(String authorsOrg) {
		this.authorsOrg = authorsOrg;
	}

	public String getYear() {
		return year;
	}

	public void setYear(String year) {
		this.year = year;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getDoi() {
		return doi;
	}

	public void setDoi(String doi) {
		this.doi = doi;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public List<TxtAuthors> getAuthors() {
		return authors;
	}

	public void setAuthors(List<TxtAuthors> authors) {
		this.authors = authors;
	}

	public String getPublisher() {
		return publisher;
	}

	public void setPublisher(String publisher) {
		this.publisher = publisher;
	}

	public String getKeywords() {
		return keywords;
	}

	public void setKeywords(String keywords) {
		this.keywords = keywords;
	}

	public String getFos() {
		return fos;
	}

	public void setFos(String fos) {
		this.fos = fos;
	}

	public Integer getTxtFile() {
		return txtFile;
	}

	public void setTxtFile(Integer txtFile) {
		this.txtFile = txtFile;
	}

	public String getfAbstract() {
		return fAbstract;
	}

	public void setfAbstract(String fAbstract) {
		this.fAbstract = fAbstract;
	}

	public String getDocType() {
		return docType;
	}

	public void setDocType(String docType) {
		this.docType = docType;
	}

	public String getVenue() {
		return venue;
	}

	public void setVenue(String venue) {
		this.venue = venue;
	}

	public Integer getIssue() {
		return issue;
	}

	public void setIssue(Integer issue) {
		this.issue = issue;
	}

	public Integer getnCitation() {
		return nCitation;
	}

	public void setnCitation(Integer nCitation) {
		this.nCitation = nCitation;
	}

	public String getVolume() {
		return volume;
	}

	public void setVolume(String volume) {
		this.volume = volume;
	}

	public String getLang() {
		return lang;
	}

	public void setLang(String lang) {
		this.lang = lang;
	}

	public String getReferences() {
		return references;
	}

	public void setReferences(String references) {
		this.references = references;
	}

	public String getIssn() {
		return issn;
	}

	public void setIssn(String issn) {
		this.issn = issn;
	}

	public String getIsbn() {
		return isbn;
	}

	public void setIsbn(String isbn) {
		this.isbn = isbn;
	}
	
}
